package com.kanq.handler;

import com.kanq.pojo.context.ChatContext;
import com.kanq.pojo.entity.KanqAiFile;
import com.kanq.service.KanqAiFileService;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class FileRetrievalHandler implements ChatHandler {
    private final KanqAiFileService fileService;

    public FileRetrievalHandler(KanqAiFileService fileService) {
        this.fileService = fileService;
    }

    @Override
    public void handle(ChatContext context) {
        if (CollectionUtils.isEmpty(context.getChunkIds())) {
            context.setFileWithChunks(new ArrayList<>());
            return;
        }
        List<KanqAiFile> fileWithChunks = fileService.getFileWithChunksV2(context.getChunkIds());
        context.setFileWithChunks(fileWithChunks);
    }
}